import Vue from 'vue'
import Router from 'vue-router'
import store from '@/store'
import DatabaseRouters from './database'
import homePageRouters from './homePage'
// import PlatformRouters from './platform'
// import SolveMethodsRouters from './solveMethods'
// import FeeManageRouters from './feeManage'
// import OrderManageRouters from './orderManage'
// import internalRouters from './internal'
// import SeaRailRouters from './SeaRail'
// import RailwayRouters from './Railway'
// import ClearanceRouters from './clearance'
// import transportaRouters from './transporta'
// import oceanRouters from './ocean'
import visualRouters from './visualization'
import systemRouters from './systemManagement'
import PermissionSettingsRouters from './PermissionSettings'
import dataManagementRouters from './dataManagement'
import masterDataRouters from './masterData'
import SugarFactoryRouters from './SugarFactory'
import summary from './summary'
import supplierRouters from './supplier'
import biddingRouters from './bidding'
import arbitrationRouters from './arbitration'
import capacityManageRouters from './capacityManage'

import queryCensusManageRouters from './queryCensus'

import orderSuperviseRouters from './orderSupervise'
import waybillRouters from './waybill'
import bidAdministerRouters from './bidAdminister'
import contractManageRouters from './contractManage'
import orderMonitorRouters from './orderMonitor'
import orderShutRouters from './orderShut'
// 平台统计
import queryCensusPRouters from './queryCensusP'
// 结算管理
import settlementRouters from './settlement'

import dealManageRouters from './dealManage'
// 供应商应收费用结算管理
import cstManagementRouters from './cstManagement'
//竞价评审管理
import bidManagementRouters from './bidManagement'

Vue.use(Router)

// bascViews
const loginPath = () => import('../views/basicViews/login/login')
const registerPath = () => import('../views/basicViews/register/index.vue')
const homePath = () => import('../views/basicViews/home')
const errorPage = () => import('../views/basicViews/Error')

// layout
const layoutPath = () => import('../views/layout')
const iframePath = () => import('../views/layout/main/iframe')

// dataBase
const dataBase = () => import('../views/dataBase')

const homePage = () => import('../views/homePage/group')

// // platform
// const platform = () =>
//   import('../views/platform')

// // solveMethods
// const solveMethods = () =>
//   import('../views/solveMethods')

// // orderManage
// const orderManage = () =>
//   import('../views/orderManage')

// // feeManage
// const feeManage = () =>
//   import('../views/feeManage')
// // clearance
// const clearance = () =>
//   import('../views/clearance')

// // internal
// const international = () =>
//   import('../views/international')

// // SeaRail
// const SeaRail = () =>
//   import('../views/SeaRail')

// // Railway
// const Railway = () =>
// import('../views/Railway')

// // transporta
// const transporta = () =>
// import('../views/transporta')

// // transporta
// const ocean = () =>
// import('../views/ocean')
//系统管理
const system = () => import('../views/systemManagement/SecondaryManagement')
//监控管理
const visual = () => import('../views/visualization/twovisualization')
//权限管理 页面对象
const SecondarySetting = () => import('../views/PermissionSettings/SecondarySetting')

const SecondaryDataManagement = () => import('../views/dataManagement/SecondaryDataManagement')

const twoMasterData = () => import('../views/masterData/twoMasterData')

const SugarFactory = () => import('../views/SugarFactory/secondarySugarFactory')

const twoArbitration = () => import('../views/arbitration/twoArbitration')

//供应商管理
const SecondarySupplier = () => import('../views/supplier/SecondarySupplier')

//招标管理
const Bidding = () => import('../views/bidding')

//订单管理
const twoOrderSupervise = () => import('../views/orderSupervise/twoOrderSupervise')
//订单管理 -- > 合同管理
const dealManage = () => import('../views/orderManage/dealManage')

//运单管理
const twoWaybill = () => import('../views/waybill/twoWaybill')

//运力管理
const twoCapacityManage = () => import('../views/capacityManage/twoCapacityManage')
//统计查询
const twoQueryCensus = () => import('../views/queryCensus/twoQueryCensus')

//竞价管理
const bidAdminister = () => import('../views/bidAdminister')

//合同管理
const contractManage = () => import('../views/contractManage')
//订单监控管理
const monitorManage = () => import('../views/orderManage/monitorManage')
//订单监控管理
const orderManage = () => import('../views/orderManage')

// 需求汇总管理
const summaryView = () => import('../views/Summary/twoSummary')

// 结算管理
const settlementView = () => import('../views/settlement/towSettlement')

// 应收费用结算管理
const cstManagementView = () => import('../views/cstManagement/twoCstManagement')

//竞价评审管理
const bidManagement = () => import('../views/bidManagement')

//消息管理
const sysMessage = () => import('../views/systemManagement/messageManageme')

// 发运情况汇总
const queryCensusPView = () => import('../views/queryCensusP')

// export default new Router({
const router = new Router({
  // mode: 'history',
  routes: [
    {
      path: '/',
      redirect: '/index',
    },
    {
      path: '/home',
      name: 'router.home',
      component: homePath,
    },
    {
      path: '/index',
      name: 'router.home',
      component: () => import('../views/web/home'),
    },
    {
      path: '/service',
      name: 'router.service',
      component: () => import('../views/web/service'),
    },
    // {
    //   path: '/news',
    //   name: 'router.news',
    //   component: () => import('../views/web/news'),
    // },
    {
      path: '/searchResult',
      name: 'router.searchResult',
      component: () => import('../views/web/news/searchResult.vue'),
    },
    {
      path: '/details/:id',
      name: 'router.newsDetails',
      component: () => import('../views/web/news/detailsPage.vue'),
    },
    {
      path: '/detailsRight/:id',
      name: 'router.detailsRight',
      component: () => import('../views/web/home/details.vue'),
    },
    {
      path: '/intro',
      name: 'router.intro',
      component: () => import('../views/web/intro'),
    },
    {
      path: '/complaint',
      name: 'router.complaint',
      component: () => import('../views/web/complaint'),
    },
    {
      path: '/onLine',
      name: 'router.onLine',
      component: () => import('../views/web/onLine'),
    },
    {
      path: '/aboutUs',
      name: 'router.aboutUs',
      component: () => import('../views/web/aboutUs'),
    },
    {
      path: '/group',
      name: 'router.group',
      component: () => import('../views/homePage/group'),
    },
    {
      path: '/forgetpasswd',
      name: 'router.forgetpasswd',
      component: () => import('../views/basicViews/forgetpasswd'),
    },
    {
      path: '/errorPage',
      name: '错误页面',
      component: errorPage,
    },

    {
      path: '/login',
      component: loginPath,
    },
    {
      path: '/register',
      component: registerPath,
    },
    {
      path: '/layout',
      // name: 'router.Statement',
      component: layoutPath,
      // redirect: '/layout/settlement/towSettlement/Statement',
      redirect: '/layout/homePage/group',
      children: [
        {
          path: 'iframe',
          name: 'router.iframe',
          component: iframePath,
        },
        {
          path: 'home',
          name: 'router.home',
          component: homePath,
        },
        {
          path: 'dataBase',
          name: 'router.dataBase',
          component: dataBase,
          children: DatabaseRouters,
        },
        {
          path: 'homePage',
          name: 'router.homePage',
          component: homePage,
          children: homePageRouters,
        },
        // {
        //   path: 'solveMethods',
        //   name: 'router.solveMethods',
        //   component: solveMethods,
        //   children: SolveMethodsRouters
        // },
        // {
        //   path: 'feeManage',
        //   name: 'router.feeManage',
        //   component: feeManage,
        //   children: FeeManageRouters
        // },
        // {
        //   path: 'clearance',
        //   name: 'router.clearance',
        //   component: clearance,
        //   children: ClearanceRouters
        // },
        // {
        //   path: 'international',
        //   name: 'router.international',
        //   component: international,
        //   children: internalRouters
        // },
        // {
        //   path: 'orderManage',
        //   name: 'router.orderManage',
        //   component: orderManage,
        //   children: OrderManageRouters
        // },
        // {
        //   path: 'SeaRail',
        //   name: 'router.SeaRail',
        //   component: SeaRail,
        //   children: SeaRailRouters
        // },
        // {
        //   path: 'Railway',
        //   name: 'router.Railway',
        //   component: Railway,
        //   children: RailwayRouters
        // },
        // {
        //   path: 'transporta',
        //   name: 'router.transporta',
        //   component: transporta,
        //   children: transportaRouters
        // },
        // {
        //   path: 'ocean',
        //   name: 'router.ocean',
        //   component: ocean,
        //   children: oceanRouters
        // },
        {
          path: 'systemManagement',
          name: 'router.system',
          component: system,
          children: systemRouters,
        },
        {
          path: 'visualization',
          name: 'router.visual',
          component: visual,
          children: visualRouters,
        },
        {
          path: 'PermissionSettings',
          name: 'router.SecondarySetting',
          component: SecondarySetting,
          children: PermissionSettingsRouters,
        },
        {
          path: 'dataManagement',
          name: 'router.SecondaryDataManagement',
          component: SecondaryDataManagement,
          children: dataManagementRouters,
        },
        {
          path: 'masterData',
          name: 'router.twoMasterData',
          component: twoMasterData,
          children: masterDataRouters,
        },
        {
          path: 'SugarFactory',
          name: 'router.SugarFactory',
          component: SugarFactory,
          children: SugarFactoryRouters,
        },
        {
          path: 'summary',
          name: 'router.summary',
          component: summaryView,
          children: summary,
        },
        {
          path: 'supplier',
          name: 'router.SecondarySupplier',
          component: SecondarySupplier,
          children: supplierRouters,
        },
        {
          path: 'bidding',
          name: 'router.Bidding',
          component: Bidding,
          children: biddingRouters,
        },
        {
          path: 'arbitration',
          name: 'router.twoArbitration',
          component: twoArbitration,
          children: arbitrationRouters,
        },
        {
          path: 'orderSupervise',
          name: 'router.twoOrderSupervise',
          component: twoOrderSupervise,
          children: orderSuperviseRouters,
        },
        {
          path: 'waybill',
          name: 'router.twoWaybill',
          component: twoWaybill,
          children: waybillRouters,
        },
        {
          path: 'bidAdminister',
          name: 'router.bidAdminister',
          component: bidAdminister,
          children: bidAdministerRouters,
        },
        {
          path: 'contractManage',
          name: 'router.contractManage',
          component: contractManage,
          children: contractManageRouters,
        },
        {
          path: 'orderManage',
          name: 'router.orderManage',
          component: orderManage,
          children: orderMonitorRouters,
        },
        {
          path: 'orderManage',
          name: 'router.monitorManage',
          component: monitorManage,
          children: orderShutRouters,
        },
        {
          path: 'orderManage',
          name: 'router.dealManage',
          component: dealManage,
          children: dealManageRouters,
        },
        // {
        //   path: 'platform',
        //   name: 'router.platformManagement',
        //   component: platform,
        //   children: PlatformRouters
        // },
        {
          path: 'capacityManage',
          name: 'router.twoCapacityManage',
          component: twoCapacityManage,
          children: capacityManageRouters,
        },
        {
          path: 'queryCensusP',
          name: 'router.queryCensusP',
          component: queryCensusPView,
          children: queryCensusPRouters,
        },
        {
          path: 'queryCensus',
          name: 'router.twoQueryCensus',
          component: twoQueryCensus,
          children: queryCensusManageRouters,
        },
        {
          path: 'settlement',
          name: 'router.settlement',
          component: settlementView,
          children: settlementRouters,
        },
        {
          path: 'cstManagement',
          name: 'router.cstManagement',
          component: cstManagementView,
          children: cstManagementRouters,
        },
        {
          path: 'bidManagement',
          name: 'router.bidManagement',
          component: bidManagement,
          children: bidManagementRouters,
        },
        {
          path: 'systemManagement',
          name: 'router.sysMessage',
          component: sysMessage,
          children: systemRouters,
        },
        {
          path: '*',
          name: '错误页面',
          component: errorPage,
        },
      ],
    },
    {
      path: '*',
      component: errorPage,
    },
  ],
})
// 有权限的 URL 集合
router.beforeEach((to, from, next) => {
  store.commit('app/CHANGE_MDL_URL', to.fullPath)
  const AUTH_URL = store.getters['user/AUTH_URL']
  if (to.fullPath.includes('layout') && to.fullPath !== '/layout') {
    if (AUTH_URL[to.fullPath]) {
      to.meta['BUTTONS'] = AUTH_URL[to.fullPath]
      // store.state.tagViews.visitedTags = []
      next()
    } else {
      // next(from)
      next()
    }
  } else {
    next()
  }
})

export default router
